package com.zhou.jiancai.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.zhou.jiancai.R;
import com.zhou.jiancai.Utils.LogUtils;
import com.zhou.jiancai.entbusData.DataSynEvent;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * Created by Administrator on 2017/6/12.
 */

public class EntBusTestActivity extends Activity {

    public DataSynEvent data;
    private TextView tv_entBus;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.entbustest);
        tv_entBus = (TextView) findViewById(R.id.tv_entBus);
        EventBus.getDefault().register(this);

        Button  Button_test= (Button) findViewById(R.id.Button_test);
        Button_test.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


             /*   data = new DataSynEvent();
                data.setCount(500);//需要传递的数据*/

               // EventBus.getDefault().post(new DataSynEvent(500));//发送消息
                Intent i =new Intent(EntBusTestActivity.this,EntBusTest1Activity.class);
                startActivity(i);
            }
        });

    }
    @Subscribe(threadMode = ThreadMode.MAIN) //在ui线程执行
    public void helloEventBus(DataSynEvent event) {
        LogUtils.d( "event---->" + event.getCount());

        tv_entBus.setText("接受到了数据"+event.getCount());


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}
